package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.model;

import java.sql.ResultSet;
import java.sql.Timestamp;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.controller.database.DatabaseConnection;

public class History
{
	@SuppressWarnings("unused")
	private DatabaseConnection connection;
	
	private static String HISTORY_ID;
	private Timestamp timestamp;
	private String user;
	private String source;
	private String description;

	//Database Column
	public static final	String TABLENAME = "cms_history";
	public static final String TC_ID = "HISTORY_ID";
	public static final String TC_TIMESTAMP = "Timestamp";
	public static final String TC_USER = "User";
	public static final String TC_SOURCE = "Source";
	public static final String TC_DESCRIPTION = "Description";
	
	public History(Timestamp timestamp, String user, String source, String description)
	{
		genHISTORY_ID(new DatabaseConnection());
		this.timestamp = timestamp;
		this.user = user;
		this.source = source;
		this.description = description;
	}

	@SuppressWarnings("static-access")
	public History(String HISTORY_ID)
	{
		this.HISTORY_ID = HISTORY_ID;
	}

	public static String getHISTORY_ID()
	{
		return HISTORY_ID;
	}
	
	private void genHISTORY_ID(DatabaseConnection connection)
	{
		this.connection = connection;
		String query = "SELECT MAX(" + ") FROM CMS_HISTORY";
		ResultSet rs = connection.query(query);
		try
		{
			while(rs.next())
			{
				HISTORY_ID = rs.getString(1);
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public Timestamp getTimestamp()
	{
		return timestamp;
	}

	public void setTimestamp(Timestamp timestamp)
	{
		this.timestamp = timestamp;
	}

	public String getUser()
	{
		return user;
	}

	public void setUser(String user)
	{
		this.user = user;
	}

	public String getSource()
	{
		return source;
	}

	public void setSource(String source)
	{
		this.source = source;
	}

	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}
}